#post请求 请求
from flask import Flask,render_template,url_for,request

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

#(常用）传参数的url。场景：接口
#http://127.0.0.1:5000/product_list?page_no=1 &cat=sport
@app.route('/product_list')
def product_list():
    args = request.args
    print(args['page_no'])
    print(args['cat'])
    #数据库查询 pass
    return '商品1，商品2...'


@app.route('/login')  #1
def login():
    print(request)
    return render_template('login.html')

@app.route('/login_submit',methods=['POST','GET'])
def login_submit():  #2
    form = request.form
    print(form)
    username=form['username']
    password=form['password']
    print(username,password)
    #跟数据库里额用户表做权限比对或存储信息
    return '表单提交完成'

#合并成login
@app.route('/login',methods=['GET','POST'])
def login():
    print(request.method)
    if request.method == 'GET':
        return render_template('login.html')
    elif request.method == 'POST':
        form_dict = request.form
        username = form_dict['username']
        password = form_dict['password']
        return '表单的请求方式{}，username:{},password:{}',format(request.method,username,password)
    else:
        pass



if __name__ == '__main__':
    app.run()


"""
request:flask框架中全局变量，存储着跟请求相关信息。

作业1：https://www.1owo.com/categories/flask/  L1-L5
作业2：print(request.method)  ,把/login /login_submit二合一 /login，第一次get请求表单页面，表单信息提交时走post请求。
"""